﻿using DataScripter.Excel.Formulas;

namespace DataScripter.Excel.Functions
{
	internal class Sum : Formula
	{
		private readonly string _cellRef1;
		private readonly string _cellRef2;
		private readonly Formula _formula1;
		private readonly Formula _formula2;

		public Sum(string cellRef1, string cellRef2)
		{
			_cellRef1 = cellRef1;
			_cellRef2 = cellRef2;
		}

		public Sum(string cellRef1, Formula formula2)
		{
			_cellRef1 = cellRef1;
			_formula2 = formula2;
		}

		public Sum(ICell cell1, Formula formula2)
		{
			_formula1 = new Reference(cell1);
			_formula2 = formula2;
		}

		public Sum(Formula formula1, Formula formula2)
		{
			_formula1 = formula1;
			_formula2 = formula2;
		}

		public Sum(ICell cellRef1, ICell cellRef2)
		{
			_formula1 = new Reference(cellRef1);
			_formula2 = new Reference(cellRef2);
		}

		#region Overrides of Formula

		public override string Resolve(ICell current)
		{
			string v1 = _cellRef1 ?? _formula1.Resolve(current);
			string v2 = _cellRef2 ?? _formula2.Resolve(current);
			return string.Format(DutchFunctionNames.SUM + "({0}:{1})", v1, v2);
		}

		#endregion
	}
}